import { useAppConfig } from '@/stores'
import { isNil } from 'lodash-es'

export const useOrderStatusCheck = {
  /** 去支付 */
  quZhiFu: (order: Record<string, any>) => {
    const appConfig = useAppConfig()
    if (appConfig.hidePayBtn) {
      return false
    }
    // return isNil(order.paymentParams)
    //   && order.status < 3
    //   && order.status !== 2
    return order.subStatus === 101 && isNil(order.paymentParams)
  },
  /** 人脸审核 */
  renLianShenHe: (order: Record<string, any>) => {
    const { appletSet } = useAppConfig()
    return order.human === 0
      && order.replenish !== 1
      && order.status < 4
      && (appletSet.openPersionFace?.value ?? '0') === '1'
  },
  /** 签署合同 - 蚂蚁？ */
  qianShuHeTong: (order: Record<string, any>) => {
    return !isNil(order.contractSignflow)
      && order.signFlowFinish < 2
  },
  /** 签署合同 - 君子签 */
  qianShuHeTong_JunZiQian: (order: Record<string, any>) => {
    return order.subStatus !== 401 && order?.jzqSignFile?.signStatus === 0
  },
  /** 签承诺书 */
  qianChengNuoShu: (order: Record<string, any>) => {
    return order.subStatus !== 401 && order?.jzqSignReceivePromiseFile?.signStatus === 0
  },
  /** 签收单 */
  qianShouDan: (order: Record<string, any>) => {
    return order.subStatus !== 401 && order.jzqSignReceivePhoneFile?.signStatus === 0
  },
  /** 签署代扣 */
  qianShuDaiKou: (order: Record<string, any>) => {
    return order.signFlowFinish === 8
  },
  /** 查看账单 */
  chaKanZhangDan: (order: Record<string, any>) => {
    return order.productOrderRecordVoList.length > 0
      && (order.status < 7 || order.status === 13)
  },
  /** 售后详情 */
  shouHouXiangQing: (order: Record<string, any>) => {
    return [4, 6].includes(order.status)
      && !isNil(order.flowOne)
  },
  /** 确认收货 */
  queRenShouHuo: (order: Record<string, any>) => {
    // return order.status === 4 && order.subStatus !== 203 && order.subStatus !== 204
    return order.subStatus === 205
  },
  /** 自提 */
  ziTi: (order: Record<string, any>) => {
    // return order.status === 3
    //   && (isNil(order.shopsUserOutGoods) || order.shopsUserOutGoods?.status === 0)
    return order.shippingMode === 1
  },
  /** 确认自提 */
  queRenZiTi: (order: Record<string, any>) => {
    return order.status === 3
      && order.shopsUserOutGoods?.status === 0
  },
  /** 申请归还 */
  shenQingGuiHuan: (order: Record<string, any>) => {
    return order.status === 5
  },
  /** 定损结果 */
  dingSunJieGuo: (order: Record<string, any>) => {
    return order.status === 6
  },
  /** 违约金 */
  weiYueJin: (order: Record<string, any>) => {
    return order.haveOverdueFine === 1
  },
  /** 续租 */
  xuZu: (order: Record<string, any>) => {
    const appConfig = useAppConfig()
    if (appConfig.hidePayBtn) {
      return false
    }
    return order.status === 5
  },
  /** 买断 */
  maiDuan: (order: Record<string, any>) => {
    const appConfig = useAppConfig()
    if (appConfig.hidePayBtn) {
      return false
    }
    return (order.status <= 6 && order.status > 2 && order.status !== 8)
      || order.status === 13
  },
  /** 取消订单 */
  quXiaoDingDan: (order: Record<string, any>) => {
    return order.status === 1
  },
  /** 申请退款 */
  shenQingTuiKuan: (order: Record<string, any>) => {
    return order.status === 2
  },
  /** 服务保障 */
  fuWuBaoZhang: (order: Record<string, any>) => {
    return order.productOrderExtra?.length > 0
  },
  /** 待风控补录 */
  daiFengKongLuRu: (order: Record<string, any>) => {
    return order.subStatus === 102
  },
  /** 待收货补录 */
  daiShouHuoLuRu: (order: Record<string, any>) => {
    return order.subStatus === 202
  },
}
